<%@ Page Language="C#"%>
<%@ Import Namespace="SubSonic" %>
<%@ Import Namespace="SubSonic.CodeGenerator" %>
<%@ Import Namespace="System.Data" %>

<%foreach(DataProvider p in DataService.Providers){

      TableSchema.Table[] tables = DataService.GetTables(p.Name);
      TableSchema.Table[] views = DataService.GetViews(p.Name);

%>
namespace <%=p.GeneratedNamespace%>
{
	#region Tables Struct
	public partial struct Tables
	{
		<%
			foreach (TableSchema.Table t in tables)
			{
			    if(CodeService.ShouldGenerate(t.Name, p.Name))
			    {
%>
		public static string <%=t.ClassName%> = @"<%=t.Name%>";
        <%
			    }
			}
%>
	}
	#endregion

    #region View Struct
    public partial struct Views 
    {
		<%
			foreach (TableSchema.Table v in views)
			{
				if (CodeService.ShouldGenerate(v.Name, p.Name))
				{
%>
		public static string <%=v.ClassName%> = @"<%=v.Name%>";
        <%
			}
		}
%>
    }
    #endregion
    
    #region Query Factories
	public static class DB{
	    public static Select Select(TableSchema.Table tbl){
	        return new Select(tbl);
	    }    
	    public static Select Select(){
	        return new Select(DataService.Providers["<%=p.Name%>"]);
	    }
		public static Select Select(params string[] columns){
	        return new Select(DataService.Providers["<%=p.Name%>"],"<%=p.Name%>");
	    }
		public static Select Select(params Aggregate[] aggregates){
	        return new Select(DataService.Providers["<%=p.Name%>"],aggregates);
	    }
	    
	    public static Update Update(string tableName){
	        return new Update(tableName, "<%=p.Name %>");
	    }
        public static Update Update(TableSchema.Table tbl){
	        return new Update(tbl);
	    }    
	    
	    public static Insert Insert(string tableName){
	        return new Insert(tableName, "<%=p.Name %>");
	    }
	    public static Insert Insert(TableSchema.Table tbl){
	        return new Insert(tbl);
	    }    
	    
	    public static Insert Insert(){
	        Insert i=new Insert();
	        i.provider=DataService.Providers["<%=p.Name%>"];
	        return i;
	    }
	    
	    public static Delete Delete(){
	        return new Delete("<%=p.Name%>");
	    }
	    
	    public static InlineQuery Query(){
   	        return new InlineQuery("<%=p.Name%>");
	    }
	}
    #endregion
    
}
<%} %>


#region Databases
public partial struct Databases 
{
	<%foreach (DataProvider p in DataService.Providers) { %>
	public static string <%= p.Name %> = @"<%= p.Name%>";
    <%}%>
}
#endregion


